package cn.nfwx.tv.widget.qpop;

import android.graphics.Color;
import android.text.TextUtils;
import android.view.Gravity;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import cn.nfwx.tv.R;
import cn.nfwx.tv.model.QpopProgram;

/**
 * Created by dell on 2018/4/8.
 */
public class QpopProgramAdapter extends BaseQuickAdapter<QpopProgram, BaseViewHolder> {

    private String playingDateStr;
    private boolean _isPlayDay;
    private int selection = -1;

    public QpopProgramAdapter() {
        super(R.layout.item_review_program);
    }

    @Override
    protected void convert(BaseViewHolder helper, QpopProgram item) {
        helper.setText(R.id.tv_qpop_name, item.getActname());
        helper.setText(R.id.tv_qpop_time, item.getStartTimeStr());

        helper.setTextColor(R.id.tv_qpop_name, Color.WHITE);
        helper.setTextColor(R.id.tv_qpop_time, Color.WHITE);
        helper.setTextColor(R.id.tv_qpop_stats, Color.WHITE);
        helper.setBackgroundColor(R.id.tv_qpop_stats, Color.TRANSPARENT);
        ((TextView)helper.getView(R.id.tv_qpop_stats)).setGravity(Gravity.CENTER);

        //LogUtil.e("ttt2", _isPlayDay + "----" + selection + "----" + helper.getLayoutPosition() + "---" + item.toString());

        if (item.getVideoValid() == 0) {
            helper.setTextColor(R.id.tv_qpop_name, Color.parseColor("#999999"));
            helper.setTextColor(R.id.tv_qpop_time, Color.parseColor("#999999"));
            helper.setTextColor(R.id.tv_qpop_stats, Color.parseColor("#999999"));
            if (TextUtils.isEmpty(item.getVideoUrl())) {
                helper.setText(R.id.tv_qpop_stats, R.string.review_preview);
                ((TextView)helper.getView(R.id.tv_qpop_stats)).setGravity(Gravity.RIGHT);
            } else {
                helper.setBackgroundRes(R.id.tv_qpop_stats, R.drawable.bg_r3_w05_99);
                helper.setText(R.id.tv_qpop_stats, R.string.review_review);
            }
        } else if (_isPlayDay && selection == helper.getLayoutPosition()) {
            helper.setTextColor(R.id.tv_qpop_name, Color.parseColor("#ff003c"));
            helper.setTextColor(R.id.tv_qpop_time, Color.parseColor("#ff003c"));
            helper.setTextColor(R.id.tv_qpop_stats, Color.parseColor("#ff003c"));

            helper.setText(R.id.tv_qpop_stats, R.string.review_playing);
        } else if (item.getVideoValid() == 1) {

            helper.setTextColor(R.id.tv_qpop_name, Color.WHITE);
            helper.setTextColor(R.id.tv_qpop_time, Color.WHITE);
            helper.setTextColor(R.id.tv_qpop_stats, Color.WHITE);
            helper.setText(R.id.tv_qpop_stats, R.string.review_review);
            helper.setBackgroundRes(R.id.tv_qpop_stats, R.drawable.bg_r3_w05_ff);

        }
    }

    /**
     * 是否是要显示正在播放的日子
     *
     * @param _isPlayDay
     */
    public void isPlayDay(boolean _isPlayDay) {
        this._isPlayDay = _isPlayDay;
    }

    /**
     * 是否是要显示正在播放的日子
     *
     * @param dateStr
     */
    public void isPlayDay(String dateStr) {
        isPlayDay(dateStr.equals(this.playingDateStr));
    }

    /**
     * 正在播放的
     *
     * @param selection
     */
    public void setSelection(int selection) {
        //LogUtil.e("ttt", selection + "");
        this.selection = selection;
        notifyDataSetChanged();
    }

    public void setDateStr(String dateStr) {
        this.playingDateStr = dateStr;
    }
}
